'''
Created on 21/04/2009

@author: eh01
'''
import logging


ROOT = 'Node'
HUB_LISTENER = 'HubListenerService'
TIMER = 'TimerService'
WEBSERVER = 'WebServerService'
DATASTORE = 'Datastore'

loggers = {}

# Initialize the logger
root_logger = logging.getLogger()
root_logger.setLevel(logging.INFO)
streamHandler = logging.StreamHandler()
formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(thread)d - %(name)s - %(message)s")
streamHandler.setFormatter(formatter)
root_logger.addHandler(streamHandler)

loggers[ROOT] = root_logger

def get_logger(application_name=ROOT):
    try:
        logger = loggers[application_name]
    except:
        logger = logging.getLogger(application_name)
        loggers[application_name] = logger
    return logger

def update_log_level(level, application_name=ROOT):
    logger = get_logger(application_name)
    logger.setLevel(level);
    
def get_loggers():
    return loggers